<?php

namespace Common\Model;

/**
 * AdminHotelModel.class实例模型
 * 
 * @author songanwei
 * @date 2016-1-4
 */
class AdminHotelModel extends BaseModel {

    protected $trueTableName = 'tb_admin_hotel';

    /**
     * 返回客栈管理员客栈关系数据
     * @modify songanwei 2016-01-04
     * @param integer $adminId  管理员ID
     * @param integer $role 角色ID
     * @return type
     */
    public function getInfosByAdmin($adminId, $role = 1) {
        if (is_array($adminId)) {
            $adminId = implode(',', $adminId);
        }
        $where = array(
            'role' => $role,
            'isdelete' => NOT_DELETE,
        );
        if (strpos($adminId, ',') === false) {
            $where['adminlogin_id'] = $adminId;
        } else {
            $where['adminlogin_id'] = array('in', $adminId);
        }

        return $this->where($where)->select();
    }

    /**
     * 返回客栈管理员客栈关系数据
     * @modify songanwei 2016-01-04
     * @param integer $hotel  折扣ID
     * @param integer $role 角色ID
     * @return type
     */
    public function getInfosByHotel($hotel, $role = 1) {
        if (is_array($hotel)) {
            $hotel = implode(',', $hotel);
        }
        $where = array(
            'role' => $role,
            'isdelete' => NOT_DELETE,
        );
        if (strpos($hotel, ',') === false) {
            $where['hotelentity_id'] = $hotel;
        } else {
            $where['hotelentity_id'] = array('in', $hotel);
        }

        return $this->where($where)->select();
    }

    /**
     * 添加客栈用户关系数据
     * @modify songanwei 2016-01-04
     * @param integer $hotelId  客栈ID
     * @param type $adminLoginId 登录ID
     * @param type $role 角色
     * @return type
     */
    public function addInfo($hotelId, $adminLoginId, $role = 1) {
        $options = array(
            'hotelentity_id' => $hotelId,
            'adminlogin_id' => $adminLoginId,
            'role' => $role
        );
        return $this->add($options);
    }

}
